#Firmware Raspberry

#Imports
import time
from datetime import datetime
from Constantes import *
from Configurator import Configurator
from Sensor import Sensor
from Database import Database
from Ports import Ports
from Script import Script
import thread

#Startup
Por = Ports("PortConf.cf","Constantes.cf")
Sen = Sensor(11,Por.ConvertirAGPIO(Por.BuscarPorTipo("PortConf.cf","sensor"),"Constantes.cf"))
Db = Database("Mediciones.db")
Script = Script()

def LecturaTempHum(delay): 
	while True:
		#Lectura del sensor y almacenamiento en la base Tabla: Mediciones
		medicion = Sen.Obtener_Datos()
		if medicion != "error":
			Temperatura, Humedad = medicion.split("_")
			Db.Insertar(Temperatura,Humedad,datetime.today())

def LeerScript():
	while True:
		Script.Ejecutar()			
def EnvioYRecepcionDatos():
	

thread.start_new_thread(LecturaTempHum(3))
thread.start_new_thread(LeerScript())
thread.start_new_thread(EnvioYRecepcionDatos())
